package free.akerigan.yafb2lib.library;

import java.util.ArrayList;
import java.util.HashMap;

import free.akerigan.yafb2lib.model.AuthorModel;
import free.akerigan.yafb2lib.model.BookModel;

public class LibraryModel {

    protected ArrayList<BookModel> bookList;

    protected HashMap<String, AuthorModel> authors;

    public LibraryModel() {
	bookList = new ArrayList<BookModel>();
	authors = new HashMap<String, AuthorModel>();
    }

    public int getSize() {
	return bookList.size();
    }

    public BookModel getBookModel(int index) {
	if (index < 0 || index > bookList.size() - 1) {
	    return null;
	} else {
	    return bookList.get(index);
	}
    }

    public int addBookModel(BookModel model) {
	if (bookList.add(model)) {
	    return bookList.size() - 1;
	} else {
	    return -1;
	}
    }

    public String addAuthor(AuthorModel author) {
	String fullName = author.getFullName();
	if (!authors.containsKey(fullName)) {
	    authors.put(fullName, author);
	}
	return fullName;
    }
}
